/**
描述
  定义一个单词的“兄弟单词”为：交换该单词字母顺序（注：可以交换任意次），而不添加、删除、修改原有的字母就能生成的单词。
  兄弟单词要求和原来的单词不同。例如： ab 和 ba 是兄弟单词。 ab 和 ab 则不是兄弟单词。
  现在给定你 n 个单词，另外再给你一个单词 x ，让你寻找 x 的兄弟单词里，按字典序排列后的第 k 个单词是什么？
  注意：字典中可能有重复单词。


  输入描述：
  输入只有一行。 先输入字典中单词的个数n，再输入n个单词作为字典单词。 然后输入一个单词x 最后后输入一个整数k


  输出描述：
  第一行输出查找到x的兄弟单词的个数m 第二行输出查找到的按照字典顺序排序后的第k个兄弟单词，没有符合第k个的话则不用输出。


  示例1
  输入：
      3 abc bca cab abc 1

  输出：
      2
      bca
*/
// const readline = require('readline')
// const rl = readline.createInterface({
//   input:process.stdin,
//   output:process.stdout
// })

function transform(input) {
  // 字符串 转数组
  const inputArr = input.split(' ')
  const fristIdx = inputArr.splice(0, 1)
  const targetHood = inputArr.splice(0, fristIdx)
  const findHood = inputArr.splice(0, 1)
  const lastIdx = inputArr.splice(0, 1)
  let brother = isBrotherHood(targetHood, findHood)
  // 按照自字符排序
  brother.sort()
  console.log(brother.length)
  if (brother.length > lastIdx - 1) console.log(brother[lastIdx - 1])
}

// 是否为 兄弟单词
function isBrotherHood(targetHood, findHood) {
  // 排序
  let tempStr = findHood.join('')
  findHood = findHood.join('').split('').sort().join('')
  return targetHood.filter((item) => {
    if (item !== tempStr) {
      // 排序后字符串相等说明是子单词
      if (item.split('').sort().join('') === findHood) {
        return item
      }
    }
  })
}

// 本地测试
// let input = '476 cb cba baad cbdb bdb acacd aba b cbbc b ccd d ddb acdab bab acc bc dccab bb daa cdcc dc adcab bd bbcab abc ba dd bdb dbbc ddbcd ab cc a c accb ddd cbc adb aad badd ad bac a addcb bcab d ccd b bc cdc acac adad d c ddc aba cac db dc aadbd bc cad baaa aaa d cddcc dabaa daa dcaac d db bab dbbbc cd acaab abbdc cda dddad a dbda cba cd dda bcca ccaca adbb bad c ba a ca d aca b bbdd dad bbcd abbcb ac aabac ca b ac dbbab bba bdcc cacbb bd a cbba badad ab ccda b c abcdc d bdab cbc ad dbcc bbddc ba caa ccac aadaa daad aacc dc dcb bca ab ccdda d cbbcc da ac b dcdba a adac ab dcc adac dd c bd bcd c ccbb dba abcb b cddc ccada dada dcca ddbbd c bda bac b bdbb bbba bdaa dda ac dd dcbbd ddccc badd adddd cba b b bbcab bcac bdad a adbd da ac adbbb cbbb caadb ab dc bdbc d c adb ab aadbd abad aaadc adcc b bbadd bbbc da acbb cbbdb bcdcc a bc ddba abadd ddc ada b bbcdc a bbccb bb a b cdac aab d dadad bad aabb dccba cd d cda b add dcacc bccdc add dc a cccd b aa ac dacbc a badb b dabbc b ddb acc c c a bc bc bcc dadc dad bba cbd b aa cbb a ababc da bc dcbcc dcbb aaad bdac ddbc bbbb bdbca d a cadac aaa dcd cc b dccba aadbd ddbbc aadb bca dcdcc a d c d b dbc abddb ccadb ccca ddda cd bbda adc ba bab adadb aaaa dbac abac acbb a cbd a dbdcd cdc c daaba a bc dabb bc aaadc b bdcc baaa addb ad dbdca cbb cbdd dc d dcbb bdd dca cad ddd cdbdd ca d c cd ddcda badb ab ba bc dcd add cc bb d dcda bbc abdb bd ba abcb d c ddaab cbbc cad bdb ba ba dbdcb dcddb dd cbdc cdd b cbcdb add bba bcaba d aba d cbcba bacb a abbca cdabc bdaa dbd bd ddc bacc bbcdc c bdbbb dd b cdc ba daaba ab b caac baad dcaca cda cbc cbdba bd dbbba aad b bbbba bbdc cdbb abc ddaa d c c bcd dcb adabd c bbc bb cd bccc ac d bbb cbd ad aad bcbaa bda ad d badba a a aa abacc cd bbbc d b ccbb dccad a ac bcbc bddc ddcad ddcb dd a dacb dddad dcb ac add ddc aa cc b ad baccb cda cbbdd adab abbdb c d bcb b ca cbdbd abbc dc abd bac bab bbb bcab cdaab bbaa 3'
// let input = '765 bac dab bbc b ddbb bbcad ddd bbbbd da bdc dbad cba dcbb bcdac aaabd ccb bbcda dadc bb ddcc dca dc a c dbbdd cba b dbbc acac dad d acbc cda cbbca a bcaa b aaa aa dcbcc acdda cbaa dcbb a c cd dd bacaa dddba c cdcc bb cc cdcd bdad dab dcabd dcdcc ca a ba cbada ccba b c bbab dbb bdcdc dddb cab addbd ba b adcc c ba a cbcdc bbd dacab b bbaa abadc bcc db bcc cb ba ab dd dca d ba daa bcd dbadc dcad cadc a dbb cccda c dcbbd ab a abac cdab dac acad aabca db ddcba ac cac bda cdb b cabca caccc bcdcd dcacb a bccdd baad dcac bbccb ccc bcdbc cac b cd acbc db db ac ac ccad aabcd bc adcd bd babba dcdd b cddb ddcac b acca abc bdb b cbbbc bca dadc badb b b bcdc c cb cbabb ccbb bdda bcccc aab b d daab ddc a ccacb c cc d cdbd bab d dcbcd dcd dddda bdb ba b cd cd b aadaa d ab abaa adac dcac dc ad a cbaad bdcd dbd cbdbd ab ba d d bbc ac ccaca d a cd ccbdb bccdb c cbda ca bbdbd b d b d dba ac dc bcddb ba bdcaa a cbda d dd bb aacb cb dcd acb d d b ac adcb adc badac bcbab aa aadb cacb ccab bccc dcdd d d ca bcdc db da ad bdbac ddccc acaac cac b c adaa abaa bcb dc adcba ccdd caa bbcb ddc aaad accd cb a dacc bbbbd b ca cdc ccac ad b da cc da b abdac ddda acaba abbb a bad cbbc cdc bc abcab adc daa da cada adbb ccad a ccc bbcbb dbdcb abcb dcb b dd d cc accdb bc da dcdcb dadc bcc aabbd cadad bb cac dbbca cd ad adc b bc bbdb a dcab dbd cdbc bdabc dbac cccdc bab ddd ad ddd bbbaa dad aaa bbabd dbadc cbdcd cc adcab a bbcda daaca ba dc cda aacbb bacdb dcd cbab aabb cba ccddc bac aba ba bb cba c acbc dba dcb acdc da abada dbbad d dbb db a adabd acaaa ad cbbab aacdd adcac ab bcadb ca ccca dbad bbbc dc dabab a cda bdb cbbcb b bb cb dbab aaaab bbb d a c aa b ddddb aaada ad bbb dcccb bb dcad bba d bd cabad adcba ddc dda ab cab acb dabac aa b a accd c a bdcab b dbcbc d bdbba dccb aaaad bbd abdc bb dc dcad adbb dba da aac ab bcbc bbbcc bdda bd adabd c ca bd bdb db bdd cbc abdb ad bdc baabd dacca add dca cba ad cba d cb cb cbbcd cddd bac ca dcbd addad adb ba d bd ddc ccaac bdd b cba c dd b ccaa dbd c c aa ac cb bcd bbb cdcbb cdbaa dca dbcda ba ba dbcba bcc abac ba adbca cda c adbaa ababc bbbda cb ccdb cabd c b b acb c a ddd abcd b cc ab b dbc a d adcc da abb cb dbda adddb ca cbabc abb d bcab ad c cbdbd acdc a bb bbadb cca cdabb aaac ccdcc dbb cd dacb abad dc db dc b adaab bc b adbbb ccda ccca aadc c dccca aaaa cc bddca bbdb a d cda bcb ddcd c cdb aaa adab ddb d ab aabc dccb cdc dacd ad abacd baacc accc cba dcab caa db bcbcc a a aa c ddca abdd cdb adcc ab ca abb abaa d cbbc cb cc cdbdb add db b add abb acac bcaa db cacba dab ac caad abddb bc cddcd bcbb aadb dd b cabb bccd dba acda acbb cac b ddccb cdbda ddba abb ddaa bd dbc ccada cc b a aab dbad dbcab dd aaca dcacc a ca c b bbb ab aabc bdcbc bc dc ba bbca db ca b c cbacb dcbdc babc aa daaa bbddd cd baac daddc bbaac d bdba cccdd b adbb c baad ddbb ddc a bdcbd c d aad b aabd cbb cca bbd cadb bccdd cabb adad aaa bcac bccdc d cd a da abbdd b bac ad dcbca bb dcdc dbc d addab ddb ba cbb da daac bb ada c bda dcab bdbdc dccac bcda abc da adb c cada c b baba aba cdaa dbbb cac daba c daa cdad dadbc bda bbdb c c ab ccdda acb bad 1'
let input = '6 cab ad abcd cba abc bca abc 1'
transform(input)

// 提交测试
// rl.on('line', (line) => {
//   if (line) {
//     // 处理接收
//     transform(line)
//   }
// })